<template>
  <div class="page-style">
    <el-tabs v-model="activeName">
      <el-tab-pane label="关联终端" name="1" />
      <el-tab-pane label="采集终端" name="2" />
    </el-tabs>
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="版本号">
        <el-input v-model="form.edition_num" placeholder="请输入版本号（例如1.0.1）" />
      </el-form-item>
      <el-form-item label="版本说明">
        <el-input v-model="form.info" type="textarea" placeholder="请输入更新说明" />
      </el-form-item>
      <el-form-item label="是否热更新">
        <el-switch
          v-model="hot_bolean"
          active-color="#13ce66"
          inactive-color="#ddd"
        />
      </el-form-item>
      <el-form-item label="更新文件">
        <el-upload
          class="upload-demo"
          action="https://fw.tfnhg.com/Portal/Oss/wgt_upload"
          :on-change="handleChange"
          :on-success="handleSuccess"
          :file-list="fileList"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { operationVersionApi, getCurrentVersionApi } from '@/api/main'
export default {
  data() {
    return {
      value: true,
      hot_bolean: false,
      form: {
        id: '',
        edition_num: '',
        edition_href: '',
        info: '',
        hot_status: 2
      },
      fileList: [],
      activeName: '1',
      appid: ''
    }
  },
  methods: {
    onSubmit() {
      this.form.id = this.activeName
      this.form.hot_status = this.hot_bolean ? '1' : '2'
      console.log(this.form)
      const data = this.form
      operationVersionApi(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success('版本更新成功！')
        }
      })
    },
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-3)
    },
    handleSuccess(res, file, fileList) {
      console.log(res, file, fileList)
      this.form.edition_href = res
    },
    getVersion() {
      const data = {
        edition_num: ''
      }
      getCurrentVersionApi(data).then(res => {
        console.log(res)
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
